package ShoppingSystem.login;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import ShoppingSystem.Admin.AdminInfo;

import ShoppingSystem.Good.shoping;



public class ObjectStreamTest {

	   static final String BASE_PATH="D:/home/";
       public static boolean Write(String path,Serializable seria){
    	
               try(
        		   FileOutputStream fos=new FileOutputStream(BASE_PATH+path);
        	       ObjectOutputStream ops=new  ObjectOutputStream(fos);
         	    )
                {
        
        	     ops.writeObject(seria);
 			     return true;
 			    
                }catch(Exception e){
         	           e.printStackTrace();
                }
       
       
           return false;
       
       }
       
 
       @SuppressWarnings("unchecked")
   	  public static <T extends Serializable> T read(Class<T> clazz, String path){
   		
   		try
   		(
   				FileInputStream fis = new FileInputStream(BASE_PATH + path);
   				ObjectInputStream ois = new ObjectInputStream(fis);
   		)
   		{
   			return (T)ois.readObject();
   		} catch (Exception e) {
   			e.printStackTrace();
   		}
   		return null;
   	}

       public static   Object readLogin(Class<Person> clazz, String path){
   		
   		try
   		(
   				FileInputStream fis = new FileInputStream(BASE_PATH + path);
   				ObjectInputStream ois = new ObjectInputStream(fis);
   		)
   		{
   			return  ois.readObject();
   		} catch (Exception e) {
   			e.printStackTrace();
   		}
   		return null;
   	}
      
       
       @SuppressWarnings("unchecked")
    	  public static <T extends Serializable> T readShop(Class<T> clazz, String path){
    		
    		try
    		(
    				FileInputStream fis = new FileInputStream(path);
    				ObjectInputStream ois = new ObjectInputStream(fis);
    		)
    		{
    			return (T)ois.readObject();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return null;
    	}

   	 
}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
